/**
 * 用户相关接口
 */
import http, { BASE_NAME, ResponseSuccessCode } from './index';

/**
 * 登录
 */
export const userLoginApi = async (value) => {
  try {
    const data = await http.post(`${BASE_NAME}/api/auth/token`, value);

    if (data.code !== ResponseSuccessCode) throw new Error('失败');

    return [null, data];
  } catch (error) {
    return [error.message, null];
  }
};

/**
 * 获取当前登录信息
 */
export async function getPersonalInformation() {
  try {
    const response = await http({
      method: 'get',
      url: `${BASE_NAME}/api/auth/current`,
    });

    return [null, response];
  } catch (e) {
    return [e.message, null];
  }
}
